#ifndef _LEX_H
#define _LEX_H

#include "Types.h"

#include <vector>
#include <string>

enum TOKEN_TYPE : u32
{
  #define AA(a, b) a,
  #include "Token.h"
};

static const char* s_TokenType[] = {
  #define AA(a, b) #a,
  #include "Token.h"
};

struct TokenInfo {
  TOKEN_TYPE    type;
  std::string   value_s;
  s64           value_n;
  int           line;
};

typedef std::vector<TokenInfo> Tokens;

class CLexer
{
public:
  void        LoadFile(char* file);
  void        DumpTokes();

  TokenInfo   GetToken();
  TokenInfo   NextToken();
  CLexer&     SkipToken();
  void        Expect(TOKEN_TYPE type);

private:
  char*       Trim(char* buf);
  char*       ScanToken(char* file_buf, TokenInfo& token);

public:
  Tokens            m_Tokes;
  Tokens::iterator  m_CurToken;
  int               m_Lines;
};

inline bool token_is_set(TokenInfo& token)
{
  return token.type >= __SET && token.type <= __XORSET;
}

inline bool token_is_comp(TokenInfo& token)
{
  return token.type >= __EQUAL && token.type <= __GEQUAL;
}

#endif  // _LEX_H
